// 导出页面为PDF格式
import html2Canvas from 'html2canvas'
import JsPDF from 'jspdf'
// html2Canvas+JsPDF导出页面为PDF格式 , 这种是纯插件方法,没有vue实体dom
export default {
  install(Vue, options) {
    Vue.prototype.getImg = function (options) {
      console.log("options",options) // 这里可以传dom名称
      // 可以写document 也可以写$refs
      // this.$refs.imageWrapper.scrollTop = 0
      html2Canvas(this.$refs.imageWrapper,{
        allowTaint: true,
        height: document.getElementById('demo').scrollHeight , // 高度有东西却显示不全
        windowHeight:document.getElementById('demo').scrollHeight,
        // width:  document.getElementById('demo').scrollWidth,//canvas宽
        useCORS: true
      }).then(canvas => {
        this.isShowScroll = true
        const link = document.createElement('a')
        link.href = canvas.toDataURL()
        link.setAttribute('download', "testimg" + '.png')
        link.style.display = 'none'
        document.body.appendChild(link)
        link.click()
      })
    }
  }
}
